package com.filldream.fastboot.web.controller.common;

import cn.hutool.core.date.DateUtil;
import com.filldream.fastboot.common.entity.R;
import com.filldream.fastboot.common.entity.db.HolidayDTO;
import com.filldream.fastboot.core.manager.HolidayManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@AllArgsConstructor
@Api(tags = "节假日接口")
@RestController
@RequestMapping("/common/holiday")
public class HolidayController {

    private HolidayManager holidayManager;

    @PostMapping("/refreshByApi")
    @ApiOperation(value = "根据API同步节假日数据")
    public R refreshByApi(){
        return holidayManager.appendHoliday(DateUtil.thisYear());
    }

    @PostMapping("/refreshByApiJson")
    @ApiOperation(value = "根据API结果同步节假日数据")
    public R refreshByApiJson(@RequestBody HolidayDTO apiJson){
        return holidayManager.appendHoliday(apiJson.getDate());
    }

    @GetMapping("/thisYearHolidayList")
    @ApiOperation(value = "获取本年节假日列表")
    public R thisYearHolidayList(){
        return R.autoSuccess( holidayManager.getListByYear(DateUtil.thisYear()) );
    }

}
